//
//  MerchentEntryViewController.m
//  gpos_app
//
//  Created by 崔航飞 on 2018/8/15.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "MerchentEntryViewController.h"
#import "Masonry.h"
#import "ClassifyView.h"
#import "LHGroupViewController.h"
#import "LHCollectionViewController.h"
#import "LHConst.h"
#import "AddPictureViewController.h"
#import "WKProgressHUD.h"
#import "GPosAPI.h"
#import "MerChantModel.h"
#import "AFNetworking.h"
#import "XMRegisterViewController.h"
#import "SVProgressHUD.h"
#import "MerChantModel.h"
#import "UIImageView+WebCache.h"
@interface MerchentEntryViewController ()<UIGestureRecognizerDelegate,UITextFieldDelegate,ClassifyViewDelegate,UINavigationControllerDelegate, UIImagePickerControllerDelegate>
@property (nonatomic,strong) UIView *backgroundViews;
@property (nonatomic,strong) UIView *viewOne;
@property (nonatomic,strong) UIView *viewTwo;
@property (nonatomic,strong) UIView *viewThree;
@property (nonatomic,strong) UIView *viewFour;
@property (nonatomic,strong) UIView *viewFive;
@property (nonatomic,strong) UIView *viewSix;
@property (nonatomic,strong) UIImageView *BottomView;
@property (nonatomic,strong) UITextField *textField1;
@property (nonatomic,strong) UITextField *textField2;
@property (nonatomic,strong) UITextField *textField3;
@property (nonatomic,strong) UITextField *textField6;
@property (nonatomic,strong) UILabel *merchantlab;
@property (nonatomic,strong) UILabel *FLLab;
@property (nonatomic,strong) WKProgressHUD *hud;
@property (nonatomic,strong) NSMutableDictionary *upDic;
@property (nonatomic,strong) NSMutableArray *imageArray;//存放处理完的图片
@property (nonatomic,strong) UIScrollView *scrolView;//滚动视图
@property (nonatomic,strong) NSMutableArray *scrollSubViews;//存放图片子视图
@property (nonatomic,strong) NSMutableArray *scrollSubFrame;//子视图的frame
@property (nonatomic,strong) NSMutableArray *localLength;//每张图片的尺寸
@property(strong,nonatomic)NSMutableArray *file;
@property (nonatomic,assign)NSInteger status;
@property (nonatomic,assign)NSInteger NUM;
@property (nonatomic,strong)NSString *address;
@property (nonatomic,assign)NSInteger ids;
@property (nonatomic,strong)NSMutableArray *pitureArr;
@property (nonatomic,strong)NSString *type;
@property (nonatomic,strong)NSString *descriptions;
@property (nonatomic,strong)NSString *name;
@property (nonatomic,strong)NSString *phones;
@property (nonatomic,strong)NSMutableArray *NewPicture;
@end

@implementation MerchentEntryViewController
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden=NO;
    self.tabBarController.tabBar.hidden=YES;
    //去掉返回的文字
    self.navigationController.navigationBar.topItem.title = @"";
    self.navigationItem.title=@"商家入驻";
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(addTP:) name:@"addPT" object:nil];
        [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
    
}
-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
    
}
#pragma mark   通知方法
-(void)addTP:(NSNotification*)noti{
    
    self.imageArray=[noti.userInfo objectForKey:@"addPicture"];
    
    [self setSpread];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    __weak typeof(self) weakSelf = self;
    self.view.backgroundColor=[UIColor whiteColor];
    self.navigationController.navigationBar.backgroundColor=[UIColor whiteColor];
    self.navigationController.navigationBar.tintColor=[UIColor blackColor];
    self.imageArray = [NSMutableArray new];
    self.pitureArr=[NSMutableArray new];
    self.NewPicture=[NSMutableArray new];
    self.file=[NSMutableArray new];
    self.upDic=[[NSMutableDictionary alloc] init];
    self.scrollSubViews = [NSMutableArray new];
    self.scrollSubFrame = [NSMutableArray new];
    self.localLength = [NSMutableArray new];
    int userID=[[[NSUserDefaults standardUserDefaults] objectForKey:@"userId"] intValue];
    NSDictionary *dic=[NSDictionary dictionaryWithObjectsAndKeys:@(userID),@"userId", nil];
    [GPosAPI requestMySelfMerchantWithParams:dic andCallback:^(id obj) {
        NSLog(@"%@",obj);
        if (obj==nil)
        {
            [SVProgressHUD showErrorWithStatus:@"请求失败,请检查您的网络状态"];
            [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
            [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
            
            
        }else{
            
            if ([[obj objectForKey:@"code"] integerValue]==200)
            {
                if ([[obj objectForKey:@"data"] count]==0)
                {
                    [weakSelf initUI:0];
                    weakSelf.NUM=0;
                }else{
                    NSMutableArray *arr=[obj objectForKey:@"data"];
                    
                    for (NSDictionary *dataDic in arr)
                    {
                        
                        weakSelf.status=[[dataDic objectForKey:@"status"] integerValue];
                        weakSelf.address=[dataDic objectForKey:@"address"];
                        weakSelf.phones=[dataDic objectForKey:@"phone"];
                        weakSelf.ids=[[dataDic objectForKey:@"id"] integerValue];
                        weakSelf.pitureArr=[dataDic objectForKey:@"picture"];
                        weakSelf.type=[dataDic objectForKey:@"type"];
                        weakSelf.descriptions=[dataDic objectForKey:@"description"];
                        weakSelf.name=[dataDic objectForKey:@"name"];
                    }
                    for (NSMutableDictionary *pictDic in weakSelf.pitureArr)
                    {
                        MerChantModel *model=[[MerChantModel alloc] init];
                        model.pictuers=[pictDic objectForKey:@"uri"];
                        NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:model.pictuers]];
                      UIImage *image = [UIImage imageWithData:data];
//                        UIImage *image = [UIImage imageWithData:data];
                        //                        UIImage *img=[self scaleFromImage:image toSize:CGSizeMake(2430, 2500)];
                        //                        UIImage *image = [[SDImageCache sharedImageCache] imageFromDiskCacheForKey:model.pictuers];
                        NSLog(@"%@",image);
                        if (image==nil)
                        {
                            
                        }else{
                        [weakSelf.imageArray addObject:image];
                        }
                    }
                    
                    if (weakSelf.status==1) {//店铺审核中
                        
                        [weakSelf initUI:1];
                        weakSelf.NUM=1;
                        
                    }else if (weakSelf.status==2){//店铺入驻成功，可以再次修改
                        
                        [weakSelf initUI:2];
                        weakSelf.NUM=2;
                    }else{//店铺审核失败，重新上传数据
                        
                        [weakSelf initUI:3];
                        weakSelf.NUM=3;
                    }
                }
                
                
            }else if ([[obj objectForKey:@"code"] integerValue]==401 || [[obj objectForKey:@"code"] intValue] == 402){
                [[NSNotificationCenter defaultCenter] postNotificationName:@"NewLoginInView" object:nil];
                UIStoryboard * mainStory = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
                XMRegisterViewController *VC = [mainStory instantiateInitialViewController];
                [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"passWord"];
                VC.hidesBottomBarWhenPushed=YES;
                //设置当前窗口的根控制器
                
                [UIApplication sharedApplication].keyWindow.rootViewController=VC;
                [SVProgressHUD showInfoWithStatus:[obj objectForKey:@"message"]];
                [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
                [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
                
                
            }else{
                
                [SVProgressHUD showErrorWithStatus:[obj objectForKey:@"message"]];
                [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
                [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
                
            }
            
        }
        
        
    }];
    
    NSDictionary *dics=@{@"":@""};
    [GPosAPI requestMerchantTypeWithParams:dics andCallback:^(id obj) {
        if (obj==nil) {
            
            weakSelf.hud=[WKProgressHUD popMessage:@"获取分类失败" inView:self.view duration:1 animated:YES];
            
        }else{
            
            if ([[obj objectForKey:@"code"] integerValue]==200)
            {
                NSMutableArray *dataArr=[NSMutableArray new];
                for (NSDictionary *daDic in [obj objectForKey:@"data"]) {
                    MerChantModel *mo=[[MerChantModel alloc] init];
                    mo.name=[daDic objectForKey:@"value"];
                    mo.type=[daDic objectForKey:@"key"];
                    [dataArr addObject:mo.name];
                    [weakSelf.upDic setValue:mo.type forKey:mo.name];
                }
                
            }else if ([[obj objectForKey:@"code"] integerValue]==401 || [[obj objectForKey:@"code"] intValue] == 402){
                
                [[NSNotificationCenter defaultCenter] postNotificationName:@"NewLoginInView" object:nil];
                UIStoryboard * mainStory = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
                XMRegisterViewController *VC = [mainStory instantiateInitialViewController];
                [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"passWord"];
                VC.hidesBottomBarWhenPushed=YES;
                //设置当前窗口的根控制器
                [UIApplication sharedApplication].keyWindow.rootViewController=VC;
                [SVProgressHUD showInfoWithStatus:[obj objectForKey:@"message"]];
                [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
                [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
                
                
            }
            else{
                
                weakSelf.hud=[WKProgressHUD popMessage:@"获取分类失败" inView:weakSelf.view duration:1 animated:YES];
                
            }
            
        }
    }];
    
    
    
}
#pragma mark --
-(void)setScrol{
    UIScrollView *scrol = [[UIScrollView alloc]init];
    scrol.frame = CGRectMake(0, 100*(SCREEN_HEIGHT/568), 320*(SCREEN_WIDTH/320), 77*(SCREEN_HEIGHT/568));
    [self.view addSubview:scrol];
    self.scrolView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
    self.scrolView = scrol;
    self.automaticallyAdjustsScrollViewInsets = NO;
}

-(void)initUI:(NSInteger)num{
    
    self.backgroundViews=[[UIView alloc] init];
    self.backgroundViews.backgroundColor=[UIColor colorWithWhite:0.94 alpha:1];
    [self.view addSubview:self.backgroundViews];
    [self.backgroundViews mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.view.mas_top).offset(kNavbarHeight);
        make.left.equalTo(self.view.mas_left);
        make.right.equalTo(self.view.mas_right);
        make.height.equalTo(@(KmainScreenHeiht - kNavbarHeight - kBottomSafeHeight));
        
    }];
    
    self.viewOne=[[UIView alloc] init];
    self.viewOne.backgroundColor=[UIColor whiteColor];
    [self.backgroundViews addSubview:self.viewOne];
    [self.viewOne mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.backgroundViews.mas_top).offset(10);
        make.left.equalTo(self.backgroundViews.mas_left);
        make.right.equalTo(self.backgroundViews.mas_right);
        make.height.equalTo(@(50));
        
    }];
    
    self.viewTwo=[[UIView alloc] init];
    self.viewTwo.backgroundColor=[UIColor whiteColor];
    [self.backgroundViews addSubview:self.viewTwo];
    [self.viewTwo mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.viewOne.mas_bottom).offset(1.2);
        make.left.equalTo(self.backgroundViews.mas_left);
        make.right.equalTo(self.backgroundViews.mas_right);
        make.height.equalTo(@(50));
        
    }];
    
    self.viewThree=[[UIView alloc] init];
    self.viewThree.backgroundColor=[UIColor whiteColor];
    [self.backgroundViews addSubview:self.viewThree];
    [self.viewThree mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.viewTwo.mas_bottom).offset(1.2);
        make.left.equalTo(self.backgroundViews.mas_left);
        make.right.equalTo(self.backgroundViews.mas_right);
        make.height.equalTo(@(50));
        
    }];
    
    self.viewFour=[[UIView alloc] init];
    self.viewFour.backgroundColor=[UIColor whiteColor];
    //    UITapGestureRecognizer *imageTaps=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(popPickerVIew:)];
    //    [self.viewFour addGestureRecognizer:imageTaps];
    [self.backgroundViews addSubview:self.viewFour];
    [self.viewFour mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.viewThree.mas_bottom).offset(10);
        make.left.equalTo(self.backgroundViews.mas_left);
        make.right.equalTo(self.backgroundViews.mas_right);
        make.height.equalTo(@(50));
        
    }];
    
    self.viewFive=[[UIView alloc] init];
    self.viewFive.backgroundColor=[UIColor whiteColor];
    [self.backgroundViews addSubview:self.viewFive];
    [self.viewFive mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.viewFour.mas_bottom).offset(1.2);
        make.left.equalTo(self.backgroundViews.mas_left);
        make.right.equalTo(self.backgroundViews.mas_right);
        make.height.equalTo(@(50));
        
    }];
    self.viewSix=[[UIView alloc] init];
    self.viewSix.backgroundColor=[UIColor whiteColor];
    [self.backgroundViews addSubview:self.viewSix];
    [self.viewSix mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.viewFive.mas_bottom).offset(1.2);
        make.left.equalTo(self.backgroundViews.mas_left);
        make.right.equalTo(self.backgroundViews.mas_right);
        make.height.equalTo(@(50));
        
    }];
    
    //确定按钮
    self.BottomView =[[UIImageView alloc] init];
    //    self.BottomView.image=[UIImage imageNamed:@"icon_anniu_f"];
    //    self.BottomView.userInteractionEnabled = YES;
    //    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(GoYes:)];
    //    tap.delegate=self;
    //    [self.BottomView addGestureRecognizer:tap];
    [self.backgroundViews addSubview:self.BottomView];
    [self.BottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.viewSix.mas_bottom).offset(40);
        make.left.equalTo(self.backgroundViews.mas_left).offset(30);
        make.right.equalTo(self.backgroundViews.mas_right).offset(-30);
        
    }];
    
    UILabel *backLab=[[UILabel alloc] init];
    //    backLab.text = @"确定";
    //    backLab.userInteractionEnabled =YES;
    //    backLab.textColor = [UIColor whiteColor];
    backLab.textAlignment = NSTextAlignmentCenter;
    [self.BottomView addSubview:backLab];
    [backLab mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.BottomView.mas_top).offset(25);
        make.left.equalTo(self.BottomView.mas_left);
        make.right.equalTo(self.BottomView.mas_right);
        make.height.equalTo(@(30));
    }];
    
    UIImageView *img1=[[UIImageView alloc] init];
    img1.image=[UIImage imageNamed:@"icon_sj"];
    [self.viewOne addSubview:img1];
    [img1 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.viewOne.mas_left).offset(15);
        make.top.equalTo(self.viewOne.mas_top).offset(18);
        
    }];
    
    UILabel *lab1=[[UILabel alloc] init];
    lab1.text=@"商户名";
    lab1.font=[UIFont systemFontOfSize:14];
    [self.viewOne addSubview:lab1];
    [lab1 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(img1.mas_right).offset(10);
        make.top.equalTo(self.viewOne.mas_top).offset(12);
        make.bottom.equalTo(self.viewOne.mas_bottom).offset(-12);
        make.width.equalTo(@(65));
    }];
    
    self.textField1=[[UITextField alloc] init];
    self.textField1.placeholder=@"请输入商店名称";
    self.textField1.delegate=self;
    self.textField1.font=[UIFont systemFontOfSize:14];
    [self.viewOne addSubview:self.textField1];
    [self.textField1 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(lab1.mas_right).offset(1);
        make.top.equalTo(self.viewOne.mas_top).offset(10);
        make.bottom.equalTo(self.viewOne.mas_bottom).offset(-10);
        make.width.equalTo(@(220));
    }];
    
    UIImageView *img2=[[UIImageView alloc] init];
    img2.image=[UIImage imageNamed:@"icon_dianhua"];
    [self.viewTwo addSubview:img2];
    [img2 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.viewTwo.mas_left).offset(15);
        make.top.equalTo(self.viewTwo.mas_top).offset(18);
        
    }];
    
    UILabel *lab2=[[UILabel alloc] init];
    lab2.text=@"电话";
    lab2.font=[UIFont systemFontOfSize:14];
    [self.viewTwo addSubview:lab2];
    [lab2 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(img2.mas_right).offset(10);
        make.top.equalTo(self.viewTwo.mas_top).offset(12);
        make.bottom.equalTo(self.viewTwo.mas_bottom).offset(-12);
        make.width.equalTo(@(65));
    }];
    
    self.textField2=[[UITextField alloc] init];
    self.textField2.placeholder=@"请输入店主电话";
    self.textField2.delegate=self;
    self.textField2.keyboardType=UIKeyboardTypeNumberPad;
    self.textField2.font=[UIFont systemFontOfSize:14];
    [self.viewTwo addSubview:self.textField2];
    [self.textField2 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(lab2.mas_right).offset(1);
        make.top.equalTo(self.viewTwo.mas_top).offset(10);
        make.bottom.equalTo(self.viewTwo.mas_bottom).offset(-10);
        make.width.equalTo(@(220));
    }];
    
    
    UIImageView *img3=[[UIImageView alloc] init];
    img3.image=[UIImage imageNamed:@"icon_dizhi"];
    [self.viewThree addSubview:img3];
    [img3 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.viewThree.mas_left).offset(15);
        make.top.equalTo(self.viewThree.mas_top).offset(18);
        
    }];
    
    UILabel *lab3=[[UILabel alloc] init];
    lab3.text=@"地址";
    lab3.font=[UIFont systemFontOfSize:14];
    [self.viewThree addSubview:lab3];
    [lab3 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(img3.mas_right).offset(10);
        make.top.equalTo(self.viewThree.mas_top).offset(12);
        make.bottom.equalTo(self.viewThree.mas_bottom).offset(-12);
        make.width.equalTo(@(65));
    }];
    
    self.textField3=[[UITextField alloc] init];
    self.textField3.placeholder=@"请输入详细地址";
    self.textField3.delegate=self;
    self.textField3.font=[UIFont systemFontOfSize:14];
    [self.viewThree addSubview:self.textField3];
    [self.textField3 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(lab3.mas_right).offset(1);
        make.top.equalTo(self.viewThree.mas_top).offset(10);
        make.bottom.equalTo(self.viewThree.mas_bottom).offset(-10);
        make.width.equalTo(@(220));
    }];
    
    
    //图片的
    UIImageView *img4=[[UIImageView alloc] init];
    img4.image=[UIImage imageNamed:@"icon_tupian"];
    [self.viewFour addSubview:img4];
    [img4 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.viewFour.mas_left).offset(15);
        make.top.equalTo(self.viewFour.mas_top).offset(18);
        
    }];
    
    UILabel *lab4=[[UILabel alloc] init];
    lab4.text=@"图片";
    lab4.font=[UIFont systemFontOfSize:14];
    [self.viewFour addSubview:lab4];
    [lab4 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(img4.mas_right).offset(10);
        make.top.equalTo(self.viewFour.mas_top).offset(12);
        make.bottom.equalTo(self.viewFour.mas_bottom).offset(-12);
        make.width.equalTo(@(65));
    }];
    
    self.merchantlab=[[UILabel alloc] init];
    //    self.merchantlab.text=@"可添加3-5张店铺图片";
    self.merchantlab.textColor=[UIColor grayColor];
    self.merchantlab.font=[UIFont systemFontOfSize:14];
    [self.viewFour addSubview:self.merchantlab];
    [self.merchantlab mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(lab4.mas_right).offset(1);
        make.top.equalTo(self.viewFour.mas_top).offset(10);
        make.bottom.equalTo(self.viewFour.mas_bottom).offset(-10);
        make.width.equalTo(@(150));
    }];
    //分类
    
    UIImageView *img5=[[UIImageView alloc] init];
    img5.image=[UIImage imageNamed:@"icon_feilei_rz"];
    [self.viewFive addSubview:img5];
    [img5 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.viewFive.mas_left).offset(15);
        make.top.equalTo(self.viewFive.mas_top).offset(20);
        
    }];
    
    UILabel *lab5=[[UILabel alloc] init];
    lab5.text=@"分类";
    lab5.font=[UIFont systemFontOfSize:14];
    [self.viewFive addSubview:lab5];
    [lab5 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(img5.mas_right).offset(10);
        make.top.equalTo(self.viewFive.mas_top).offset(12);
        make.bottom.equalTo(self.viewFive.mas_bottom).offset(-12);
        make.width.equalTo(@(65));
    }];
    
    self.FLLab=[[UILabel alloc] init];
    //    self.FLLab.text=@"请选择店铺类型";
    self.FLLab.textColor=[UIColor grayColor];
    self.FLLab.font=[UIFont systemFontOfSize:14];
    [self.viewFive addSubview:self.FLLab];
    [self.FLLab mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(lab5.mas_right).offset(1);
        make.top.equalTo(self.viewFive.mas_top).offset(10);
        make.bottom.equalTo(self.viewFive.mas_bottom).offset(-10);
        make.width.equalTo(@(150));
    }];
    
    //    UITapGestureRecognizer *popTap=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(popTaps:)];
    //    popTap.delegate=self;
    //    [self.viewFive addGestureRecognizer:popTap];
    //
    UIImageView *img6=[[UIImageView alloc] init];
    img6.image=[UIImage imageNamed:@"icon_huodong"];
    [self.viewSix addSubview:img6];
    [img6 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.viewSix.mas_left).offset(15);
        make.top.equalTo(self.viewSix.mas_top).offset(18);
        
    }];
    
    UILabel *lab6=[[UILabel alloc] init];
    lab6.text=@"活动";
    lab6.font=[UIFont systemFontOfSize:14];
    [self.viewSix addSubview:lab6];
    [lab6 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(img6.mas_right).offset(10);
        make.top.equalTo(self.viewSix.mas_top).offset(12);
        make.bottom.equalTo(self.viewSix.mas_bottom).offset(-12);
        make.width.equalTo(@(65));
    }];
    self.textField6=[[UITextField alloc] init];
    self.textField6.placeholder=@"例: 消费满100送20GPOS";
    self.textField6.adjustsFontSizeToFitWidth = YES;
    self.textField6.delegate=self;
    self.textField6.font=[UIFont systemFontOfSize:14];
    [self.viewSix addSubview:self.textField6];
    [self.textField6 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(lab6.mas_right).offset(1);
        make.top.equalTo(self.viewSix.mas_top).offset(10);
        make.bottom.equalTo(self.viewSix.mas_bottom).offset(-10);
        make.width.equalTo(@(220));
    }];
    
    UIScrollView *scrol = [[UIScrollView alloc]init];
    //    scrol.frame = CGRectMake(CGRectGetMaxX(lab4.frame), 0, 320*(SCREEN_WIDTH/320), 50);
    self.scrolView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
    self.scrolView = scrol;
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.scrolView.showsVerticalScrollIndicator = YES;
    
    self.scrolView.showsHorizontalScrollIndicator = YES;
    [self.viewFour addSubview:scrol];
    [scrol mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(lab4.mas_right).offset(0);
        make.top.equalTo(self.viewFour.mas_top).offset(7.5);
        make.bottom.equalTo(self.viewFour.mas_bottom).offset(-7.5);
        make.right.equalTo(self.viewFour.mas_right).offset(-5);
    }];
    
    if (num==0)
    {
        self.textField1.text=@"";//商户名
        self.textField2.text=@"";//电话
        self.textField3.text=@"";//地址
        self.textField6.text=@"";//活动
        self.merchantlab.text=@"可添加3-5张店铺图片";
        self.FLLab.text=@"请选择店铺类型";
        UITapGestureRecognizer *popTap=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(popTaps:)];
        popTap.delegate=self;
        [self.viewFive addGestureRecognizer:popTap];
        
        UITapGestureRecognizer *imageTaps=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(popPickerVIew:)];
        [self.viewFour addGestureRecognizer:imageTaps];
        self.BottomView.image=[UIImage imageNamed:@"icon_anniu_f"];
        self.BottomView.userInteractionEnabled = YES;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(GoYes:)];
        tap.delegate=self;
        [self.BottomView addGestureRecognizer:tap];
        backLab.text = @"确定";
        backLab.userInteractionEnabled =YES;
        backLab.textColor = [UIColor whiteColor];
        
    }else if (num==1){
        self.textField1.text=[NSString stringWithFormat:@"%@",self.name];//商户名
        self.textField2.text=[NSString stringWithFormat:@"%@",self.phones];//电话
        self.textField3.text=[NSString stringWithFormat:@"%@",self.address];//地址
        self.textField6.text=[NSString stringWithFormat:@"%@",self.descriptions];//活动
        self.merchantlab.text=@"";
        self.FLLab.text=[NSString stringWithFormat:@"%@",self.type];
        self.textField1.userInteractionEnabled=NO;
        self.textField2.userInteractionEnabled=NO;
        self.textField3.userInteractionEnabled=NO;
        self.textField6.userInteractionEnabled=NO;
        self.BottomView.image=[UIImage imageNamed:@"icon_anniu_h"];
        self.BottomView.userInteractionEnabled = NO;
        
        backLab.text = @"店铺审核中";
        backLab.userInteractionEnabled =NO;
        backLab.textColor = [UIColor whiteColor];
        [self setSpread];
    }else if (num==2){
        
        self.textField1.text=[NSString stringWithFormat:@"%@",self.name];//商户名
        self.textField2.text=[NSString stringWithFormat:@"%@",self.phones];//电话
        self.textField3.text=[NSString stringWithFormat:@"%@",self.address];//地址
        self.textField6.text=[NSString stringWithFormat:@"%@",self.descriptions];//活动
        self.merchantlab.text=@"";
        self.FLLab.text=[NSString stringWithFormat:@"%@",self.type];
        self.textField1.userInteractionEnabled=YES;
        self.textField2.userInteractionEnabled=YES;
        self.textField3.userInteractionEnabled=YES;
        self.textField6.userInteractionEnabled=YES;
        self.BottomView.image=[UIImage imageNamed:@"icon_anniu_f"];
        self.BottomView.userInteractionEnabled = YES;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(GoYes:)];
        tap.delegate=self;
        [self.BottomView addGestureRecognizer:tap];
        UITapGestureRecognizer *popTap=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(popTaps:)];
        popTap.delegate=self;
        backLab.text = @"店铺入驻成功,点击再次修改";
        backLab.userInteractionEnabled =NO;
        backLab.textColor = [UIColor whiteColor];
        UITapGestureRecognizer *imageTaps=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(popPickerVIew:)];
        [self.viewFour addGestureRecognizer:imageTaps];
        [self setSpread];
    }else if (num==3){
        
        self.textField1.text=[NSString stringWithFormat:@"%@",self.name];//商户名
        self.textField2.text=[NSString stringWithFormat:@"%@",self.phones];//电话
        self.textField3.text=[NSString stringWithFormat:@"%@",self.address];//地址
        self.textField6.text=[NSString stringWithFormat:@"%@",self.descriptions];//活动
        self.merchantlab.text=@"";
        self.FLLab.text=[NSString stringWithFormat:@"%@",self.type];
        self.textField1.userInteractionEnabled=YES;
        self.textField2.userInteractionEnabled=YES;
        self.textField3.userInteractionEnabled=YES;
        self.textField6.userInteractionEnabled=YES;
        self.BottomView.image=[UIImage imageNamed:@"icon_anniu_f"];
        self.BottomView.userInteractionEnabled = YES;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(GoYes:)];
        tap.delegate=self;
        [self.BottomView addGestureRecognizer:tap];
        backLab.text = @"店铺审核失败";
        backLab.userInteractionEnabled =YES;
        self.viewFive.userInteractionEnabled = YES;
        UITapGestureRecognizer *popTap=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(popTaps:)];
        popTap.delegate=self;
        backLab.textColor = [UIColor whiteColor];
        UITapGestureRecognizer *imageTaps=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(popPickerVIew:)];
        [self.viewFour addGestureRecognizer:imageTaps];
        [self setSpread];
    }
    
}
//添加图片的点击事件
-(void)popPickerVIew:(UITapGestureRecognizer *)tp{
    
    
    AddPictureViewController *vc=[[AddPictureViewController alloc] init];
    if (self.status==1 || self.status==2 || self.status==3)
    {
        vc.arrs=self.imageArray;
    }
    [self.navigationController pushViewController:vc animated:YES];
    /*
     UIAlertController *alert = [[UIAlertController alloc]init];
     UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
     UIAlertAction *deleteAction = [UIAlertAction actionWithTitle:@"本地" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
     [self acquireLocal];
     }];
     UIAlertAction *archiveAction = [UIAlertAction actionWithTitle:@"相机" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
     [self acquireAlbum];
     }];
     [alert addAction:cancelAction];
     [alert addAction:deleteAction];
     [alert addAction:archiveAction];
     [self presentViewController:alert animated:YES completion:nil];
     */
}
//分类点击事件
-(void)popTaps:(UITapGestureRecognizer *)tp{
    self.viewFive.userInteractionEnabled=NO;
    if (tp.state == UIGestureRecognizerStateEnded){//该判断的作用是防止手势多次点击后重复加载页面
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            self.viewFive.userInteractionEnabled=YES;
        });
    [self.textField1 resignFirstResponder];
    [self.textField2 resignFirstResponder];
    [self.textField3 resignFirstResponder];
    [self.textField6 resignFirstResponder];
    __weak typeof(self) weakSelf = self;
    self.upDic=[NSMutableDictionary new];
    NSDictionary *dic=@{@"":@""};
    [GPosAPI requestMerchantTypeWithParams:dic andCallback:^(id obj) {
        if (obj==nil) {
            
            weakSelf.hud=[WKProgressHUD popMessage:@"获取分类失败" inView:self.view duration:1 animated:YES];
            
        }else{
            
            if ([[obj objectForKey:@"code"] integerValue]==200)
            {
                NSMutableArray *dataArr=[NSMutableArray new];
                for (NSDictionary *daDic in [obj objectForKey:@"data"]) {
                    MerChantModel *mo=[[MerChantModel alloc] init];
                    mo.name=[daDic objectForKey:@"value"];
                    mo.type=[daDic objectForKey:@"key"];
                    [dataArr addObject:mo.name];
                    [weakSelf.upDic setValue:mo.type forKey:mo.name];
                }
                ClassifyView *popView=[[ClassifyView alloc] init];
                
                [popView getCityData:dataArr];
                
                popView.delegate=self;
            }else if ([[obj objectForKey:@"code"] integerValue]==401 || [[obj objectForKey:@"code"] intValue] == 402){
                
                [[NSNotificationCenter defaultCenter] postNotificationName:@"NewLoginInView" object:nil];
                UIStoryboard * mainStory = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
                XMRegisterViewController *VC = [mainStory instantiateInitialViewController];
                [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"passWord"];
                VC.hidesBottomBarWhenPushed=YES;
                //设置当前窗口的根控制器
                [UIApplication sharedApplication].keyWindow.rootViewController=VC;
                [SVProgressHUD showInfoWithStatus:[obj objectForKey:@"message"]];
                [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
                [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
                
                
            }
            else{
                
                weakSelf.hud=[WKProgressHUD popMessage:@"获取分类失败" inView:self.view duration:1 animated:YES];
                
            }
            
        }
    }];
    }
}
-(void)backName:(NSString *)Name{
    
    self.FLLab.text=Name;
    self.FLLab.textColor=[UIColor blackColor];
    
}
//确定按钮的点击事件
-(void)GoYes:(UIGestureRecognizer *)tp{
    
    NSLog(@"%ld",[self.upDic count]);
    NSInteger types;
    //    if ([self.upDic count]==0)
    //    {
    //        types=[self.type integerValue];
    //    }else{
    
    types=[[self.upDic objectForKey:self.FLLab.text] integerValue];
    //    }
    if (self.textField1.text.length==0)
    {
        self.hud=[WKProgressHUD popMessage:@"请填写商店名称" inView:self.view duration:1 animated:YES];
    }else if (self.textField2.text.length==0){
        
        self.hud=[WKProgressHUD popMessage:@"请填写店主电话" inView:self.view duration:1 animated:YES];
        
    }else if (self.textField3.text.length==0){
        
        self.hud=[WKProgressHUD popMessage:@"请填写详细地址" inView:self.view duration:1 animated:YES];
        
    }else if (self.imageArray.count==0){
        
        self.hud=[WKProgressHUD popMessage:@"请选择店铺图片" inView:self.view duration:1 animated:YES];
        
    }else if ([self.FLLab.text isEqualToString:@"请选择店铺类型"]){
        
        self.hud=[WKProgressHUD popMessage:@"请选择店铺类型" inView:self.view duration:1 animated:YES];
        
    }else if (self.textField6.text.length==0){
        
        self.hud=[WKProgressHUD popMessage:@"请填写店铺活动" inView:self.view duration:1 animated:YES];
        
    }else{//商家入驻的网络请求
        
        AFHTTPSessionManager *manager=[AFHTTPSessionManager manager];
        manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html",@"text/plain", nil];
        
        // 2.设置证书模式
        NSString * cerPath = [[NSBundle mainBundle] pathForResource:@"www.gpos-wallet.com" ofType:@"cer"];
        NSData * cerData = [NSData dataWithContentsOfFile:cerPath];
        manager.securityPolicy.pinnedCertificates = [[NSArray alloc] initWithObjects:cerData, nil];
        // 客户端是否信任非法证书
        manager.securityPolicy.allowInvalidCertificates = YES;
        // 是否在证书域字段中验证域名
        [manager.securityPolicy setValidatesDomainName:NO];
        manager.requestSerializer = [AFJSONRequestSerializer serializer];//请求
        manager.responseSerializer = [AFHTTPResponseSerializer serializer];//响应
        
        
        [manager.requestSerializer setValue:@"iphone"forHTTPHeaderField:@"user-agent"];
        [manager.requestSerializer setValue:[[NSUserDefaults standardUserDefaults] objectForKey:@"user_token"]forHTTPHeaderField:@"user-token"];
        [manager.requestSerializer setValue:[[NSUserDefaults standardUserDefaults] objectForKey:@"userId"]forHTTPHeaderField:@"userId"];
        
        manager.requestSerializer.timeoutInterval = 50;
        for (UIImage *img in self.imageArray)
        {
            //压缩图片
            NSData *Data =UIImageJPEGRepresentation(img,0.5);
            
            [self.file addObject:Data];
        }
        /*
         参数：userId
         参数：name
         参数：type
         参数：phone
         参数：address
         参数：file
         
         */
        NSLog(@"%ld",types);
        int userId=[[[NSUserDefaults standardUserDefaults] objectForKey:@"userId"] intValue];
        NSDictionary *dic=[NSDictionary dictionaryWithObjectsAndKeys:@(userId),@"userId",self.textField1.text,@"name",@(types),@"type",self.textField2.text,@"phone",self.textField3.text,@"address",self.textField6.text,@"description", nil];
        NSString* IPStr = @"https://192.168.0.111:8000/pos-gpos-app/mall/settled";
// 正式地址       NSString* IPStr = @"http://148.163.164.19:8085/mall/settled";
        [manager POST:IPStr parameters:dic constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData) {
            for ( NSData *imageDatas  in self.file)
            {
                NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
                formatter.dateFormat = @"yyyyMMddHHmmss";
                NSString *str = [formatter stringFromDate:[NSDate date]];
                NSString *fileName = [NSString stringWithFormat:@"%@.jpg", str];
                //上传的参数(上传图片，以文件流的格式)
                [formData appendPartWithFileData:imageDatas
                                            name:@"file"
                                        fileName:fileName
                                        mimeType:@"image/jpeg"];
                
            }
        } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nonnull responseObject) {
            
            
            [self.navigationController popViewControllerAnimated:YES];
            NSDictionary *dataDic=[NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
            NSLog(@"%@",dataDic);
            if (dataDic==nil) {
                [SVProgressHUD showErrorWithStatus:@"请求失败,请检查您的网络状态"];
                [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
                [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
            }else{
                
                if ([[dataDic objectForKey:@"code"] integerValue]==200)
                {
                    self.hud=[WKProgressHUD popMessage:@"提交成功" inView:self.view duration:1 animated:YES];
                    [[NSNotificationCenter defaultCenter] postNotificationName:@"uploadCurrentView" object:nil];
                }else if ([[dataDic objectForKey:@"code"] integerValue]==401 || [[dataDic objectForKey:@"code"] intValue] == 402){
                    
                    [[NSNotificationCenter defaultCenter] postNotificationName:@"NewLoginInView" object:nil];
                    UIStoryboard * mainStory = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
                    XMRegisterViewController *VC = [mainStory instantiateInitialViewController];
                    [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"passWord"];
                    VC.hidesBottomBarWhenPushed=YES;
                    //设置当前窗口的根控制器
                    [UIApplication sharedApplication].keyWindow.rootViewController=VC;
                    [SVProgressHUD showInfoWithStatus:[dataDic objectForKey:@"message"]];
                    [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
                    [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
                    
                    
                }else{
                    
                    [SVProgressHUD showErrorWithStatus:[dataDic objectForKey:@"message"]];
                    [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
                    [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
                }
            }
            
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            
        }];
        
    }
    
}
#pragma textFieldDelagate(限制输入的电话长度)
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
    
    if (textField == self.textField1) {
        //这里的if时候为了获取删除操作,如果没有次if会造成当达到字数限制后删除键也不能使用的后果.
        if (range.length == 1 && string.length == 0) {
            return YES;
        }
        else if (self.textField1.text.length >= 20) {
            self.textField1.text = [textField.text substringToIndex:20];
            return NO;
        }
    }
    if (textField == self.textField2) {
        //这里的if时候为了获取删除操作,如果没有次if会造成当达到字数限制后删除键也不能使用的后果.
        if (range.length == 1 && string.length == 0) {
            return YES;
        }
        else if (self.textField2.text.length >= 11) {
            self.textField2.text = [textField.text substringToIndex:11];
            return NO;
        }
    }
    if (textField == self.textField3) {
        //这里的if时候为了获取删除操作,如果没有次if会造成当达到字数限制后删除键也不能使用的后果.
        if (range.length == 1 && string.length == 0) {
            return YES;
        }
        else if (self.textField3.text.length >= 50) {
            self.textField3.text = [textField.text substringToIndex:50];
            return NO;
        }
    }
    if (textField == self.textField6) {
        //这里的if时候为了获取删除操作,如果没有次if会造成当达到字数限制后删除键也不能使用的后果.
        if (range.length == 1 && string.length == 0) {
            return YES;
        }
        else if (self.textField6.text.length >= 20) {
            self.textField6.text = [textField.text substringToIndex:20];
            return NO;
        }
    }
    return YES;
}


#pragma mark -获取本地图片
-(void)acquireLocal{
    LHGroupViewController *group = [[LHGroupViewController alloc]init];
    if (self.imageArray.count==0)
    {
        group.maxChooseNumber = 5;
    }else{
        
        group.maxChooseNumber = 5-self.imageArray.count;
        
    }
    
    __weak MerchentEntryViewController *weakSelf = self;
    group.backImageArray = ^(NSMutableArray<PHAsset *> *array){
        __strong MerchentEntryViewController *strongSelf = weakSelf;
        if (array) {
            for (int i = 0; i<array.count; i++) {
                PHAsset *asset = array[i];
                [[LHPhotoList sharePhotoTool]requestImageForAsset:asset size:CGSizeMake(1080, 1920) resizeMode:PHImageRequestOptionsResizeModeFast completion:^(UIImage *image, NSDictionary *info) {
                    NSString *length  = [NSString stringWithFormat:@"%f*%f",image.size.width,image.size.height];
                    [self.localLength addObject:length];
                    [self.imageArray addObject:image];
                    //加载在页面中
                    [strongSelf setSpread];
                }];
            }
        }
    };
    [self presentViewController:[[UINavigationController alloc] initWithRootViewController:group] animated:YES completion:nil];
}
#pragma mark -获取相机相册
-(void)acquireAlbum{
    UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera;
    if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera])
    {
        UIImagePickerController *picker = [[UIImagePickerController alloc] init];
        picker.delegate = self;
        picker.sourceType = sourceType;
        if ([[[UIDevice currentDevice].systemVersion componentsSeparatedByString:@"."].firstObject integerValue]  == 8) {
            self.modalPresentationStyle = UIModalPresentationOverCurrentContext;
        }
        [self presentViewController:picker animated:YES completion:nil];
    }else
    {
        NSLog(@"模拟其中无法打开照相机,请在真机中使用");
    }
}
- (UIImage *) scaleFromImage: (UIImage *) image toSize: (CGSize) size {
    UIGraphicsBeginImageContext(size);
    [image drawInRect:CGRectMake(0, 0, size.width, size.height)];
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return newImage;
}
#pragma mark --
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(nonnull NSDictionary<NSString *,id> *)info {
    __block UIImage *originalImage = [info objectForKey:UIImagePickerControllerOriginalImage];
    __weak MerchentEntryViewController *weakSelf = self;
    void(^imageBlock)() = ^(UIImage *image){
        __strong MerchentEntryViewController *strongSelf = weakSelf;
        if (!image) {
            image = [info objectForKey:UIImagePickerControllerOriginalImage];
        }
        NSString *length  = [NSString stringWithFormat:@"%f*%f",image.size.width,image.size.height];
        [strongSelf.localLength addObject:length];
        [strongSelf.imageArray addObject:image];
    };
    void(^dismissBlock)() = ^(){//声明
        __strong MerchentEntryViewController *strongSelf = weakSelf;
        [picker dismissViewControllerAnimated:YES completion:^{
            [strongSelf setSpread];
        }];
    };
    //写入本地
    [[LHPhotoList sharePhotoTool]saveImageToAblum:originalImage completion:^(BOOL success, PHAsset *asset) {
        if (success) {//存成功
            [[LHPhotoList sharePhotoTool]requestImageForAsset:asset size:CGSizeMake(1080, 1920) resizeMode:PHImageRequestOptionsResizeModeFast completion:^(UIImage *image, NSDictionary *info) {
                originalImage = [UIImage imageWithData:UIImageJPEGRepresentation(originalImage, 1) scale:originalImage.scale];
                imageBlock(originalImage);
                dismissBlock();
            }];
        }else{//存取失败
            dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
                originalImage = [UIImage imageWithData:UIImageJPEGRepresentation(originalImage, 1) scale:originalImage.scale];
                imageBlock(originalImage);
                dispatch_sync(dispatch_get_main_queue(), ^{
                    dismissBlock();
                });
            });
        }
    }];
}
#pragma mark -展示UI在界面
-(void)setSpread{
    //    UIImageView *image=[[UIImageView alloc] initWithFrame:CGRectMake(0, 500, 30, 30)];
    //    image.image=self.imageArray[0];
    self.scrolView.contentSize = CGSizeMake((imageWidth+10)*self.imageArray.count, 77*(SCREEN_HEIGHT/568));
    //    [self.scrolView addSubview:image];
    
    for (NSInteger i = self.scrollSubViews.count; i<self.imageArray.count; i++) {
        UIView *itemView = [[UIView alloc]init];
        itemView.frame = CGRectMake(imageWidth*i+10*i+80, 8, imageWidth, imageWidth);
        itemView.backgroundColor = [UIColor whiteColor];
        
        //        [self.scrolView addSubview:itemView];
        [self.viewFour addSubview:itemView];
        
        if (self.imageArray.count>0)
        {
            self.merchantlab.hidden=YES;
        }else{
            
            self.merchantlab.hidden=NO;
        }
        UIImageView *imageView = [[UIImageView alloc]init];
        imageView.frame = CGRectMake(0, 0, imageWidth, imageWidth);
        imageView.image = self.imageArray[i];
        imageView.userInteractionEnabled = YES;
        imageView.contentMode = UIViewContentModeScaleAspectFill;
        imageView.clipsToBounds = YES;
        imageView.tag = 600 +i;
        [itemView addSubview:imageView];
        //手势
        UIButton *deleteBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        deleteBtn.frame = CGRectMake(imageWidth - 12 , -3, 16, 16);
        deleteBtn.tag = 500+i;
        
        [deleteBtn setImage:[UIImage imageNamed:@"02"] forState:UIControlStateNormal];
        [deleteBtn addTarget:self action:@selector(deleteImage:) forControlEvents:UIControlEventTouchUpInside];//删除
        //        [itemView addSubview:deleteBtn];
        
        [self.scrollSubFrame addObject:[NSValue valueWithCGRect:itemView.frame]];
        [self.scrollSubViews addObject:itemView];
        [UIView animateWithDuration:0.2 animations:^{
            itemView.alpha = 1;
            
        } completion:nil];
    }
    
    
}
#pragma mark -上传
-(void)toUpload{
    for (int i = 0; i<self.imageArray.count; i++) {
        NSData *data = UIImageJPEGRepresentation(self.imageArray[i], 0.5);
        NSString *string = self.localLength[i];
        NSLog(@"%@---%lu",string,(unsigned long)data.length);
        NSLog(@"%@",self.imageArray);
    }
}
#pragma mark -删除图片
-(void)deleteImage:(UIButton *)btn{
    UIView *view  = btn.superview;
    NSInteger idx = [_scrollSubViews indexOfObject:view];
    [_scrollSubViews removeObject:view];
    [_imageArray removeObjectAtIndex:idx];
    [_localLength removeObjectAtIndex:idx];
    [_scrollSubFrame removeLastObject];
    [UIView animateWithDuration:0.2 animations:^{
        view.alpha = 0;
    } completion:^(BOOL finished) {
        [view removeFromSuperview];
        self.scrolView.contentSize = CGSizeMake(imageWidth*self.scrollSubViews.count, imageWidth);
        [UIView animateWithDuration:0.2 animations:^{
            for (NSInteger i = idx; i < self.scrollSubViews.count; i++) {
                UIView *item = self.scrollSubViews[i];
                item.frame = [(NSValue*)(self.scrollSubFrame[i]) CGRectValue];
            }
        } completion:^(BOOL finished) {
            if (finished) {
                //完成之后处理的code
                if (self.imageArray.count>0)
                {
                    self.merchantlab.hidden=YES;
                }else{
                    
                    self.merchantlab.hidden=NO;
                }
            }
        }];
    }];
}
#pragma mark --
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    [self dismissViewControllerAnimated:YES completion:nil];
}

#pragma mark
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}
@end
